package com.neu.carbon.mes.controller;

import java.util.List;

import com.neu.carbon.mes.domain.MesProcessCheck;
import com.neu.carbon.scm.domain.ScmPurchaseArrive;
import com.neu.carbon.scm.domain.ScmPurchaseContract;
import com.neu.carbon.scm.domain.ScmPurchaseSupplier;
import com.neu.carbon.scm.service.IScmPurchaseArriveService;
import com.neu.carbon.scm.service.IScmPurchaseContractService;
import com.neu.carbon.scm.service.IScmPurchaseSupplierService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.enums.BusinessType;
import com.neu.carbon.mes.domain.WmsInWarehouseApply;
import com.neu.carbon.mes.service.IWmsInWarehouseApplyService;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 入库申请审核Controller
 * 
 * @author neuedu
 * @date 2024-09-12
 */
@Api(tags = {"入库申请审核"})
@RestController
@RequestMapping("/wmsApply/inWarehouseApplyAudit")
public class WmsInWarehouseApplyController extends BaseController
{
    @Autowired
    private IWmsInWarehouseApplyService wmsInWarehouseApplyService;
    @Resource
    private IScmPurchaseArriveService iScmPurchaseArriveService;
    @Resource
    private IScmPurchaseSupplierService iScmPurchaseSupplierService;
    @Resource
    private IScmPurchaseContractService iScmPurchaseContractService;



    /**
     * 查询入库申请审核列表
     */
    @GetMapping("/list")
    @ApiOperation("查询入库申请审核列表")
    @DynamicResponseParameters(properties = {
	        @DynamicParameter(name = "total", value = "总记录数"),
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "rows", value = "返回业务数据（数组类型）", dataTypeClass = WmsInWarehouseApply.class),
            @DynamicParameter(name = "msg", value = "返回消息内容")
    })
    public TableDataInfo list(WmsInWarehouseApply wmsInWarehouseApply)
    {
        startPage();
        List<WmsInWarehouseApply> list = wmsInWarehouseApplyService.selectWmsInWarehouseApplyList(wmsInWarehouseApply);
        list.forEach(model->{

            if(model.getApplyUser().equals("1")){
                model.setApplyUserName("管理员");
            }
            if(model.getAuditUser().equals("1")){
                model.setAuditUserName("管理员");
            }
            ScmPurchaseArrive scmPurchaseArrive = iScmPurchaseArriveService.selectScmPurchaseArriveById(model.getBizBillId());
            if (scmPurchaseArrive!=null){
                model.setBizBillName(scmPurchaseArrive.getArriveNo());
            }
            ScmPurchaseSupplier scmPurchaseSupplier = iScmPurchaseSupplierService.selectScmPurchaseSupplierById(model.getSupplierId());
            if (scmPurchaseSupplier!=null){
                model.setSupplierName(scmPurchaseSupplier.getName());
            }
            ScmPurchaseContract scmPurchaseContract = iScmPurchaseContractService.selectScmPurchaseContractById(model.getContractId());
            if (scmPurchaseContract!=null){
                model.setContractName(scmPurchaseContract.getContractNo());
            }

        });


        return getDataTable(list);
    }

    /**
     * 导出入库申请审核列表
     */
    @ApiOperation("导出入库申请审核列表")
    @DynamicResponseParameters(properties = {
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "msg", value = "文件名")
    })
    @PreAuthorize("@ss.hasPermi('wmsApply:inWarehouseApplyAudit:export')")
    @Log(title = "入库申请审核", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WmsInWarehouseApply wmsInWarehouseApply)
    {
        List<WmsInWarehouseApply> list = wmsInWarehouseApplyService.selectWmsInWarehouseApplyList(wmsInWarehouseApply);
        ExcelUtil<WmsInWarehouseApply> util = new ExcelUtil<WmsInWarehouseApply>(WmsInWarehouseApply.class);
        return util.exportExcel(list, "inWarehouseApplyAudit");
    }

    /**
     * 获取入库申请审核详细信息
     */
    @ApiOperation("获取入库申请审核详细信息")
    @DynamicResponseParameters(properties = {
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "data", value = "返回业务数据", dataTypeClass = WmsInWarehouseApply.class),
            @DynamicParameter(name = "msg", value = "返回消息内容")
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        WmsInWarehouseApply model = wmsInWarehouseApplyService.selectWmsInWarehouseApplyById(id);

        if(model.getApplyUser().equals("1")){
            model.setApplyUserName("管理员");
        }
        if(model.getAuditUser().equals("1")){
            model.setAuditUserName("管理员");
        }
        ScmPurchaseArrive scmPurchaseArrive = iScmPurchaseArriveService.selectScmPurchaseArriveById(model.getBizBillId());
        if (scmPurchaseArrive!=null){
            model.setBizBillName(scmPurchaseArrive.getArriveNo());
        }
        ScmPurchaseSupplier scmPurchaseSupplier = iScmPurchaseSupplierService.selectScmPurchaseSupplierById(model.getSupplierId());
        if (scmPurchaseSupplier!=null){
            model.setSupplierName(scmPurchaseSupplier.getName());
        }
        ScmPurchaseContract scmPurchaseContract = iScmPurchaseContractService.selectScmPurchaseContractById(model.getContractId());
        if (scmPurchaseContract!=null){
            model.setContractName(scmPurchaseContract.getContractNo());
        }
        return AjaxResult.success();
    }

    /**
     * 新增入库申请审核
     */
    @ApiOperation("新增入库申请审核")
    @DynamicResponseParameters(properties = {
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "msg", value = "返回消息内容")
    })
    @PreAuthorize("@ss.hasPermi('wmsApply:inWarehouseApplyAudit:add')")
    @Log(title = "入库申请审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsInWarehouseApply wmsInWarehouseApply)
    {
        return toAjax(wmsInWarehouseApplyService.insertWmsInWarehouseApply(wmsInWarehouseApply));
    }

    /**
     * 修改入库申请审核
     */
    @ApiOperation("修改入库申请审核")
    @DynamicResponseParameters(properties = {
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "msg", value = "返回消息内容")
    })
    @PreAuthorize("@ss.hasPermi('wmsApply:inWarehouseApplyAudit:edit')")
    @Log(title = "入库申请审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsInWarehouseApply wmsInWarehouseApply)
    {
        return toAjax(wmsInWarehouseApplyService.updateWmsInWarehouseApply(wmsInWarehouseApply));
    }

    /**
     * 删除入库申请审核
     */
    @ApiOperation("删除入库申请审核")
    @DynamicResponseParameters(properties = {
            @DynamicParameter(name = "code", value = "状态码，200正确，其他错误"),
            @DynamicParameter(name = "msg", value = "返回消息内容")
    })
    @PreAuthorize("@ss.hasPermi('wmsApply:inWarehouseApplyAudit:remove')")
    @Log(title = "入库申请审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsInWarehouseApplyService.deleteWmsInWarehouseApplyByIds(ids));
    }
}
